import {getProductionLines} from "../../dao/auth";

const state = {
  productionLines: [],
  productionLine: ''
}

const getters = {
  productionLines: state => state.productionLines,
  productionLine: state => state.productionLine
}

const mutations = {
  SET_PRODUCTION_LINES(state, val) {
    state.productionLines = val
  },
  SET_PRODUCTION_LINE(state, val) {
    state.productionLine = val
  }
}

const actions = {
  loadProductionLines({ commit }) {
    return new Promise((resolve, reject) => {
      getProductionLines().then(res => {
        if (res) {
          commit('SET_PRODUCTION_LINES', res)
          resolve('ok')
        }
      }).catch(e => {
        reject(e)
      })
    })
  }
}

export default {
  state,
  getters,
  mutations,
  actions
}
